import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {//专门存储数据的地方
    num: 10,
    name: "陈龙"
  },
  mutations: {//改变state的唯一方式
    INCREMENT(state) {
      state.num++
    },
    DECREMENT(state) {
      state.num--
    },
    SET_NAME(state) {
      state.name = "黄少天"
    }
  },
  actions: {
    //action是用来触发mutation来改变state
    CHANGE_NAME({ commit }) {
      commit("SET_NAME")
    }
  }
});
